package com.wontube.smr.bo.sites.fs.conf;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.wontube.client.extension.utils.FileUtils;


/**
 * @author yuechao
 *
 */
public final class FourShared {
	private static final Logger logger = LoggerFactory.getLogger(FourShared.class);
	public static final FourShared fs = new FourShared();
	
	private boolean isUseMp3Skull = true;
	private String username = "iskyfull@gmail.com";
	private String password = "music@wontube";

	private FourShared() {
	}
	
	public FourShared load(File file) {
		String json = "";
		if (file.exists()) {
			try {
				json = FileUtils.readAllText(file);
			} catch (IOException e) {
				logger.error(e.toString());
			}
		}
		
		if (!"".equals(json)) {
			Gson gson = new Gson();
			Type type = new TypeToken<HashMap<String, String>>(){}.getType();
			Map<String, String> map = gson.fromJson(json, type);
			this.isUseMp3Skull = !"false".equalsIgnoreCase(map.get("isUseMp3Skull"));
			this.username = map.get("username");
			this.password = map.get("password");
		}
		
		logger.info("loaded 4shared config, isUseMp3Skull = {}", this.isUseMp3Skull);
		
		return this;
	}
	
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public boolean isUseMp3Skull() {
		return this.isUseMp3Skull;
	}

	public void setUseMp3Skull(boolean isUseMp3Skull) {
		this.isUseMp3Skull = isUseMp3Skull;
	}
}
